const utils = {
	isEmpty(ele) {
		if (typeof ele === 'undefined') {
			return true;
		} else if (ele == null) {
			return true;
		} else if (ele == 'null') {
			return true;
		} else if (ele == '') {
			return true;
		}
		return false;
	},
	strEmpty(ele) {
		if (typeof ele === 'undefined') {
			return "";
		} else if (ele == null) {
			return "";
		} else if (ele == 'null') {
			return "";
		} else if (ele == '') {
			return "";
		}
		return ele;
	},
	numEmpty(ele) {
		if (typeof ele === 'undefined') {
			return 0;
		} else if (ele == null) {
			return 0;
		} else if (ele == 'null') {
			return 0;
		} else if (ele == '') {
			return 0;
		}
		return Number(ele);
	},
	bankAk(acount) {
		return acount.replace(/(?<=\d{4})\d+(?=\d{4})/, " **** **** ")
	},
	getThisData(time) {
		var date = new Date(time);
		var year = date.getFullYear();
		var month = ("0" + (date.getMonth() + 1)).slice(-2);
		var day = ("0" + date.getDate()).slice(-2);
		var hour = ("0" + date.getHours()).slice(-2);
		var minutes = ("0" + date.getMinutes()).slice(-2);
		var seconds = ("0" + date.getSeconds()).slice(-2);
		return year + '.' + month + '.' + day + "/" + hour + ':' + minutes;
	},
	getDate(type) {
		var date = new Date();
		var year = date.getFullYear();
		var month = ("0" + (date.getMonth() + 1)).slice(-2);
		var day = date.getDate();
		// var hours = date.getHours();
		// var minu = date.getMinutes();
		// var sec = date.getSeconds();
		if (type == 'Y') {
			return year;
		}
		if (type == 'M') {
			return month;
		}
		if (type == 'D') {
			return day;
		}
		if (type == 'YM') {
			return year + '年' + month + "月";
		}
		if (type == 'Y-M') {
			return year + '-' + month;
		}
		if (type == 'YMD') {
			return year + '年' + month + "月" + day + "日";
		}
		if (type == 'Y-M-D') {
			return year + '-' + month + "-" + day;
		}
		return year + '-' + month + '-' + day;
	},
	tips(str, duration) {
		uni.showToast({
			title: str,
			icon: 'none',
			duration: duration ? duration : 1500
		})
	},
	jump(url, isLogin) {
		if (url == '/pages/home/home' || url == '/pages/store/store' ||
			url == '/pages/goods-cart/goods-cart' || url == '/pages/ucenter/ucenter') {
			uni.switchTab({
				url: url
			});
		} else {
			if (isLogin) {
				if (uni.getStorageSync('access_token')) {
					uni.navigateTo({
						url: url
					});
					return
				}
				// #ifdef APP-PLUS || H5
				uni.navigateTo({
					url: '/pages/login/login'
				});
				// #endif
				// #ifdef MP-WEIXIN
				uni.navigateTo({
					url: '/pages/wx-login/wx-login'
				});
				// #endif
				return;
			}
			uni.navigateTo({
				url: url
			});
		}
	},
	onTimeBack(duration) {
		setTimeout(function() {
			uni.navigateBack({
				delta: 1
			});
		}, duration ? duration : 500);
	},
	// 支付
	pay(provider, orderInfo, success, fail, complete) {
		// #ifdef APP-PLUS
		uni.requestPayment({
			provider: provider,
			orderInfo: orderInfo,
			success(res) {
				success && success(res.data);
			},
			fail(err) {
				uni.showToast({
					title: '支付失败',
					icon: 'none',
					duration: 2000
				});
				fail && fail(err.data);
			},
			complete(ress) {
				complete && complete(ress.data);
			},
		});
		// #endif
		// #ifdef MP-WEIXIN
		uni.requestPayment({
			provider: 'wxpay',
			timeStamp: orderInfo.timeStamp,
			nonceStr: orderInfo.nonceStr,
			package: orderInfo.package,
			signType: 'MD5',
			paySign: orderInfo.paySign,
			success: function(res) {
				success && success(res.data);
			},
			fail: function(err) {
				uni.showToast({
					title: '支付失败',
					icon: 'none',
					duration: 2000
				});
				fail && fail(err.data);
			},
			complete(ress) {
				complete && complete(ress.data);
			}
		});
		// #endif
	},
};

export default utils